<template>
	<div class="app-columns-container flexrbc">
		<div class="app-left-container">

			<div class="model-container">
				<div class="current-time">{{currentDateTime}}</div>
				<div class="model-handel-container">
					<div class='model-handel-btn pointer' @click="modelSpritesChange(0)"
						:class="[typeIndex===0?'handle-active':'']">全部
					</div>
					<div class='model-handel-btn pointer' @click="modelSpritesChange(1)"
						:class="[typeIndex===1?'handle-active':'']">几何模态
					</div>
					<div class='model-handel-btn pointer' @click="modelSpritesChange(2)"
						:class="[typeIndex===2?'handle-active':'']">力学模态
					</div>
					<div class='model-handel-btn pointer' @click="modelSpritesChange(4)"
						:class="[typeIndex===4?'handle-active':'']">电学模态
					</div>
					<div class='model-handel-btn pointer' @click="modelSpritesChange(5)"
						:class="[typeIndex===5?'handle-active':'']">热学模态
					</div>
					<div class='model-handel-btn pointer' @click="modelSpritesChange(6)"
						:class="[typeIndex===6?'handle-active':'']">声学模态
					</div>
				</div>
				<div class="model-control-container pointer" :class="[isModelControl?'handle-active':'']"
					@click="handleModelControl">模型控制</div>
				<div id="model-container">
				</div>
				<div style="position: fixed;left:99999999px">
					<img src="@/assets/images/icon/bg1.png" alt="complete" id="completeBg" width="300" height="140" />
				</div>
			</div>
		</div>

		<div class="app-right-container">
			<template v-if='isModelControl'>
				<div class="app-right-title">模型控制器</div>
				<div class='app-controls-container flexccc'>
					<div class="app-controls-title">正常运行</div>
					<div class="model-controls-btns flexrac">
						<div class="model-handel-btn pointer"
							:class="[animationIndex===1?'handle-active':'',isAnimating?'preventClick':'']"
							@click="floorAni(1,'up')">上行</div>
						<div class="model-handel-btn pointer"
							:class="[animationIndex===2?'handle-active':'',isAnimating?'preventClick':'']"
							@click="floorAni(2,'down')">下行</div>
					</div>
					<div class="app-controls-title">运行速度</div>
					<div class="model-controls-btns flexrac" style="padding: 12px 20px;">
						<el-input v-model="Vm" placeholder="只能输入0-1.15之间的任意数字" @input="handleSpeedInput"></el-input>
					</div>
					<div class="app-controls-title">加速度</div>
					<div class="model-controls-btns flexrac" style="padding: 12px 20px;">
						<el-input v-model="Acce" placeholder="只能输入0-1.00之间的任意数字"
							@input="handleAcceSpeedInput"></el-input>
					</div>
					<!-- <div class="model-controls-btns flexrac">
						<div class="model-handel-btn pointer"
							:class="[animationIndex===3?'handle-active':'',isAnimating?'preventClick':'']"
							@click="doorAni(1)">一楼电梯门</div>
						<div class="model-handel-btn pointer"
							:class="[animationIndex===4?'handle-active':'',isAnimating?'preventClick':'']"
							@click="doorAni(2)">二楼电梯门</div>
					</div>
					<div class="model-controls-btns flexrac">
						<div class="model-handel-btn pointer"
							:class="[animationIndex===5?'handle-active':'',isAnimating?'preventClick':'']"
							@click="operationAni(1)">一楼电梯运行</div>
						<div class="model-handel-btn pointer"
							:class="[animationIndex===6?'handle-active':'',isAnimating?'preventClick':'']"
							@click="operationAni(2)">二楼电梯运行</div>
					</div> -->
					<!-- <div class="app-controls-title">风险演化场景</div>
					<div class="model-controls-btns flexrac">
						<div class="model-handel-btn pointer" :class="[animationIndex===7?'handle-active':'']"
							@click='changeAnimation(7)'>直梯坠落</div>
						<div class="model-handel-btn pointer" :class="[animationIndex===8?'handle-active':'']"
							@click='changeAnimation(8)'>直梯冲顶</div>
					</div>
					<div class="model-handel-btn pointer" style='width:200px'
						:class="[animationIndex===9?'handle-active':'']" @click='changeAnimation(9)'>直梯门系统开关异常</div>
					<div class="model-handel-btn pointer" style='width:200px'
						:class="[animationIndex===10?'handle-active':'']" @click='changeAnimation(10)'> 直梯门系统强度退化
					</div> -->
				</div>
			</template>
			<template v-else>
				<sensorList :data='dataList' :type='typeIndex'></sensorList>
			</template>
		</div>
	</div>
</template>


<script>
	import api from "@/api/http.js";
	import sensorList from "../components/sensorList.vue";
	// 模型开始
	import * as THREE from 'three'
	import {
		GLTFLoader
	} from 'three/examples/jsm/loaders/GLTFLoader';
	import {
		OrbitControls
	} from 'three/examples/jsm/controls/OrbitControls';
	import {
		EffectComposer
	} from "three/examples/jsm/postprocessing/EffectComposer"
	import {
		RenderPass
	} from "three/examples/jsm/postprocessing/RenderPass"
	import {
		OutlinePass
	} from "three/examples/jsm/postprocessing/OutlinePass"
	import {
		GammaCorrectionShader
	} from 'three/examples/jsm/shaders/GammaCorrectionShader';
	import {
		ShaderPass
	} from "three/examples/jsm/postprocessing/ShaderPass"
	import {
		FXAAShader
	} from "three/examples/jsm/shaders/FXAAShader";
	// 模型结束
	import {
		Loading
	} from 'element-ui';
	const configUrl = window.IP;
	// import data from '/src/utils/json/data.js'
	export default {
		name: "elevatorIndex",
		data() {
			return {
				data: [],
				isModelControl: false,
				isAnimating: false,
				loadingInstance: null,
				// 模型开始
				scene: null, //场景
				renderer: null, //渲染器
				camera: null, //相机 
				light: null,
				container: null, //容器 
				modelsArray: [],

				controls: null, //控制器 
				composer: null,
				outlinePass: null,
				renderPass: null,
				animateId: null,
				zhitikuangjia: {},
				yeyinlun: {},
				yeyinddaoshenlun: {},
				jiaoxiangdaoshenlun: {},
				duizhongdaoshenlun: {},
				duizhong: {},
				jiaoxiang: {},

				youmen1: {},
				zuomen1: {},
				youmen2: {},
				zuomen2: {},
				doorleft: {},
				doorright: {},

				yeyinlungangsishen: {},
				duizhonggangsishent: {},
				yijiegangsishen: {},

				duizhonggudingduan: {},
				jiaoxianggudingduan: {},

				modelsArray2: [],
				// 电梯传感器-编码器
				bianmaqi1: {},
				bianmaqi2: {},
				// 电梯传感器-电流传感器
				dianliu1: {},
				dianliu2: {},
				dianliu3: {},
				dianliu4: {},
				dianliu5: {},
				dianliu6: {},
				dianliu7: {},
				dianliu8: {},
				// 电梯传感器-电压传感器
				dianya1: {},
				dianya2: {},
				dianya3: {},
				dianya4: {},
				dianya5: {},
				dianya6: {},
				dianya7: {},
				// 电梯传感器-高斯计
				gaosiji1: {},
				gaosiji2: {},
				gaosiji3: {},
				// 电梯传感器-激光测距仪
				jiguangceju1: {},
				jiguangceju2: {},
				// 电梯传感器-激光传感器
				jiguang: {},
				// 电梯传感器-拉压传感器
				laya1: {},
				laya2: {},
				// 电梯传感器-温度传感器
				wendu1: {},
				wendu2: {},
				wendu3: {},
				wendu4: {},
				// 电梯传感器-噪声传感器
				zaoshen1: {},
				zaoshen2: {},
				// 电梯传感器-振动传感器
				zd1: {},
				zd2: {},
				zd3: {},
				zd4: {},
				zd5: {},
				zd6: {},
				//电梯的最大运行速度m/s，后期接口可以接入,最大值1.15
				Vm: 0.35,
				//电梯运行加速度，后期接口可以接入,最大值1.00
				Acce: 1,
				// 电梯一楼到二楼的运行距离m。
				St: 2.95,
				//电梯运行时间
				totalDuration: null,
				modelControls: {
					zhitikuangjia: {
						x: 0,
						y: -10,
						z: 0
					}, //直梯框架
					yeyinlun: {
						x: -0.743,
						y: 11.839,
						z: 0
					}, //曳引轮
					yeyinddaoshenlun: {
						x: -1.709,
						y: 10.282,
						z: 0.11
					}, //曳引导绳轮
					duizhongdaoshenlun: {
						x: -2.065,
						y: 6.336,
						z: 0.44
					}, //对重导绳轮
					duizhong: {
						x: -2,
						y: 3.63,
						z: 1.324
					}, //对重
					jiaoxiangdaoshenlun: {
						x: 0,
						y: -0.305,
						z: 0.11
					}, //轿厢导绳轮
					jiaoxiang: {
						x: 0,
						y: -1.031,
						z: 0.11
					}, //轿厢
					youmen1: {
						x: 1.69,
						y: -2.779,
						z: -0.47
					}, //一楼右门
					zuomen1: {
						x: 1.69,
						y: -2.779,
						z: 0.47
					}, //一楼左门
					youmen2: {
						x: 1.69,
						y: 5.23,
						z: -0.47
					}, //二楼右门
					zuomen2: {
						x: 1.69,
						y: 5.23,
						z: 0.47
					}, //二楼左门
					doorleft: {
						x: 0.135,
						y: -1.2,
						z: -0.14 + 0.11
					}, //轿厢左门
					doorright: {
						x: 0.135,
						y: -1.2,
						z: -0.211
					}, //轿厢右门
					yeyinlungangsishen: {
						x: 0.265,
						y: 10.6,
						z: 0
					}, //曳引轮钢丝绳
					duizhonggangsishen: {
						x: 0.275,
						y: 9.08,
						z: 0.03
					}, //对重钢丝绳
					yijiegangsishen: {
						x: -2.139,
						y: 7.853,
						z: 0.818
					}, //曳引轮固定钢丝绳
					duizhonggudingduan: {
						x: 0.265,
						y: 10.598,
						z: 0
					}, //对重固定
					jiaoxianggudingduan: {
						x: -0.205,
						y: 9.305,
						z: 0.21
					}, //轿厢固定端

					//各传感器位置
					bianmaqi1: {
						x: -0.933,
						y: 11.128,
						z: -0.044
					}, //编码器1-轿厢位移
					bianmaqi2: {
						x: -0.933,
						y: 11.128,
						z: -0.044
					}, //编码器2-曳引轮转速（两个一样的，可同时测量位移和转速）

					dianliu1: {
						x: 1.237,
						y: -1.46,
						z: -0.044
					}, //电流传感器1-电学-门机输入电流-**随着轿厢位移**
					dianliu2: {
						x: -1.693,
						y: 9.823,
						z: 1.8
					}, //电流传感器2-电学-曳引机U相电流
					dianliu3: {
						x: -1.693,
						y: 9.823,
						z: 1.9
					}, //电流传感器3-电学-曳引机V相电流
					dianliu4: {
						x: -1.693,
						y: 9.823,
						z: 2.0
					}, //电流传感器4-电学-曳引机W相电流
					dianliu5: {
						x: -1.139,
						y: 10.15,
						z: 1.69
					}, //电流传感器5-电学-制动器电阻电流
					dianliu6: {
						x: -1.598,
						y: 12.284,
						z: -0.316
					}, //电流传感器6-电学-制动器线圈1电流
					dianliu7: {
						x: 0.034,
						y: 12.284,
						z: -0.257
					}, //电流传感器7-电学-制动器线圈2电流
					dianliu8: {
						x: -0.731,
						y: 12.627,
						z: -0.62
					}, //电流传感器8-电学-制动总电流

					dianya1: {
						x: 1.237,
						y: -1.61,
						z: -0.406
					}, //电压传感器1-电学-门机输入电压-**随着轿厢位移**
					dianya2: {
						x: -0.773,
						y: 9.823,
						z: 1.8
					}, //电压传感器2-电学-曳引机U相电压
					dianya3: {
						x: -0.773,
						y: 9.823,
						z: 1.9
					}, //电压传感器3-电学-曳引机V相电压
					dianya4: {
						x: -0.773,
						y: 9.823,
						z: 2.0
					}, //电压传感器4-电学-曳引机W相电压
					dianya5: {
						x: -0.939,
						y: 12.636,
						z: -0.398
					}, //电压传感器5-电学-制动器电源电压
					dianya6: {
						x: 0.018,
						y: 12.284,
						z: -0.316
					}, //电压传感器6-电学-制动器线圈1电压
					dianya7: {
						x: -1.584,
						y: 12.284,
						z: -0.257
					}, //电压传感器7-电学-制动器线圈2电压

					gaosiji1: {
						x: -0.731,
						y: 11.443,
						z: -0.488
					}, //高斯计1-电学（电磁）-磁感应强度
					gaosiji2: {
						x: 0.087,
						y: 11.941,
						z: -0.441
					}, //高斯计2-电学（电磁）-制动器1余磁
					gaosiji3: {
						x: -1.632,
						y: 12.044,
						z: -0.441
					}, //高斯计3-电学（电磁）-制动器2余磁

					jiguangceju1: {
						x: 0.112,
						y: 11.678,
						z: -0.06
					}, //激光测距仪1-几何-制动器1间隙
					jiguangceju2: {
						x: -1.576,
						y: 11.873,
						z: -0.064
					}, //激光测距仪2-几何-制动器2间隙

					jiguang: {
						x: -2.158,
						y: 10.405,
						z: 0.77
					}, //激光传感器-力学-轿厢称重

					laya1: {
						x: 1.459,
						y: -1.844,
						z: 0.43
					}, //拉压传感器1-力学-门机关门力-**随着轿厢位移**
					laya2: {
						x: 1.43,
						y: -1.804,
						z: -0.18
					}, //拉压传感器2-力学-门机开门力-**随着轿厢位移**

					wendu1: {
						x: -0.36,
						y: 11.833,
						z: -0.5
					}, //温度传感器1-热学-曳引机温度
					wendu2: {
						x: -1.564,
						y: 12.281,
						z: -0.151
					}, //温度传感器2-热学-制动器1温度
					wendu3: {
						x: 0.026,
						y: 12.281,
						z: -0.151
					}, //温度传感器3-热学-制动器2温度
					wendu4: {
						x: -0.17,
						y: 12.041,
						z: -0.06
					}, //温度传感器4-热学-曳引轮温度

					zaoshen1: {
						x: 0.344,
						y: 10.666,
						z: 0.008
					}, //噪声传感器1-声学-机房噪音
					zaoshen2: {
						x: 0,
						y: -2.27,
						z: 0
					}, //噪声传感器2-声学-轿顶噪音-**随着轿厢位移**

					zd1: {
						x: -0.76,
						y: -2.35,
						z: 0
					}, //振动传感器1-几何-轿架振动-**随着轿厢位移**
					zd2: {
						x: -0.741,
						y: 11.778,
						z: -0.212
					}, //振动传感器2-几何-曳引机轴承振动
					zd3: {
						x: 1.506,
						y: -2.33,
						z: -0.7
					}, //振动传感器3-几何-右轿门振动-随着轿厢位移-**随着轿厢位移**
					zd4: {
						x: -1.614,
						y: 12.241,
						z: -0.391
					}, //振动传感器4-几何-制动器1振动
					zd5: {
						x: 0.138,
						y: 12.246,
						z: -0.372
					}, //振动传感器5-几何-制动器2振动
					zd6: {
						x: 1.52,
						y: -2.33,
						z: 0.46
					}, //振动传感器6-几何-左轿门振动-**随着轿厢位移**
				},
				clonedModels: [], // 用于存储复制的模型
				clonedModelsA1: [], // 用于存储复制的模型
				clonedModelsA2: [], // 用于存储复制的模型
				clonedModelsA3: [], // 用于存储复制的模型
				clonedModelsA4: [], // 用于存储复制的模型

				clonedModelsB: [], // 用于存储复制的模型
				clonedModelsB1: [], // 用于存储复制的模型
				clonedModelsB2: [], // 用于存储复制的模型
				clonedModelsB3: [], // 用于存储复制的模型
				clonedModelsB4: [], // 用于存储复制的模型
				currentCount: 73, // 当前模型数量
				currentCount2: 403, // 当前模型数量

				clonedModelsC: [], // 用于存储复制的模型
				clonedModelsC1: [], // 用于存储复制的模型
				clonedModelsC2: [], // 用于存储复制的模型
				clonedModelsC3: [], // 用于存储复制的模型
				clonedModelsC4: [], // 用于存储复制的模型

				clonedModelsD: [], // 用于存储复制的模型
				clonedModelsD1: [], // 用于存储复制的模型
				clonedModelsD2: [], // 用于存储复制的模型
				clonedModelsD3: [], // 用于存储复制的模型
				clonedModelsD4: [], // 用于存储复制的模型
				// 模型结束 
				currentDateTime: '2025-02-06 17：00：10', //当前时间  
				scaleNum: 1,
				modelUrl: '',
				typeIndex: 0,
				animationIndex: '',
				timer: null,
				typeMeshMap: {
					0: '传感器',
					1: '几何',
					2: '力学',
					3: '光学',
					4: '电学',
					5: '热学',
					6: '声学'
				},
				allDeviceMeshes: [],
				currentSprites: [],
				currentOutlineObjects: [],
				ropeInstancesA: null,
				ropeInstancesB: null,
				ropeInstancesC: null,
				ropeInstancesD: null,
				instanceCount: 500,
			}
		},
		components: {
			sensorList
		},
		computed: {
			resourUrl() {
				return configUrl.resourUrl;
			},
			httpsSet() {
				return configUrl.httpsSet;
			},
			elevatorNumber() {
				return this.$store.state.settings.elevatorNumber;
			},
			dataList() {
				// typeIndex === 0 全部
				if (this.typeIndex === 0) {
					return this.data
				} else if (this.typeIndex === 1) {
					// typeIndex===1 几何模态;
					return this.data.filter(item => item.type === "几何")
				} else if (this.typeIndex === 2) {
					// typeIndex===2 力学模态;
					return this.data.filter(item => item.type === "力学")
				} else if (this.typeIndex === 3) {
					// typeIndex===3 光学模态;
					return this.data.filter(item => item.type === "光学")
				} else if (this.typeIndex === 4) {
					// typeIndex===4 电学模态;
					return this.data.filter(item => item.type === "电学")
				} else if (this.typeIndex === 5) {
					// typeIndex===5 热学模态；
					return this.data.filter(item => item.type === "热学")
				} else if (this.typeIndex === 6) {
					// typeIndex===6 声学模态；
					return this.data.filter(item => item.type === "声学")
				}

			},
		},
		beforeDestroy() {
			this.scene = null
			this.camera = null
			this.renderer = null
			this.controls = null;
			this.container = null;
			this.composer = null;
			this.outlinePass = null;
			this.renderPass = null;
			this.animateId = null;
			if (this.timer) {
				clearInterval(this.timer);
				this.timer = null;
			}
			if (this.loadingInstance) {
				this.loadingInstance.close()
			}
		},
		created() {
			this.initData();
			this.timer = setInterval(() => this.initData(), 1000);
			if (/Edge\/\d./i.test(navigator.userAgent)) {
				const version = parseInt(navigator.userAgent.match(/Edge\/(\d+)/)[1], 10);
				if (version < 79) {
					console.log('old-edge');
				}
			};

		},
		mounted() {
				this.startPeriodicRequest();
			
			// this.getPointNewData();
			// this.init();
			// this.animate();
			// this.loadingInstance = Loading.service({
			// 	text: '加载中',
			// 	target: '#model-container',
			// 	background: 'rgba(0,0,0,0.2)'
			// });
			this.$nextTick(() => {
				window.addEventListener('resize', () => {
					// 设置摄像机视锥体的长宽比（覆盖创建相机时的长宽比）
					if (this.camera && this.container) {
						this.camera.aspect = this.container.clientWidth / this.container.clientHeight;
						// 更新摄像机投影矩阵。在任何参数被改变以后必须被调用。
						this.camera.updateProjectionMatrix();
					}
					if (this.renderer && this.container) {
						// 设置渲染区尺寸
						this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
						// 设置设备像素比
						this.renderer.setPixelRatio(window.devicePixelRatio);
					}
				})
			});



		},
		methods: {
			handleSpeedInput() {
				const value = parseFloat(this.Vm);
				if (isNaN(value)) {
					this.$message.error('请输入有效的数字');
				} else if (value <= 0 || value > 1.15) {
					this.$message.error('输入的数字必须在 0 - 1.15 之间');
				} else {
					console.log(this.Vm, '运行速度')
				}
			},
			handleAcceSpeedInput() {
				const value = parseFloat(this.Acce);
				if (isNaN(value)) {
					this.$message.error('请输入有效的数字');

				} else if (value <= 0 || value > 1) {
					this.$message.error('输入的数字必须在 0 - 1.00 之间');
				} else {
					console.log(this.Acce, '加速度')
				}
			},
			getPointNewData() {
				let params = {
					dataPoints: [{
						cusdeviceNo: '0000258543000001',
						identifier: 'Var_ZDQ_A'
					}]
				}
				api.getPointNewData(params).then(res => {
					console.log(res, 'getPointNewData')
				})
			},
			getCusdevicesPoints() {
					let params = {
						cusdeviceNo: '0000258543000001'
					}
					api.getCusdevicesPoints(params).then(res => {
						console.log(res, '获取第一个电梯的传感器');
						this.data = res.data.data
					}).catch(err => {
						console.log(err, '获取第一个电梯的传感器err')
					})
			},
			// 启动定时请求（使用setTimeout递归实现）
			async startPeriodicRequest() {
			    try {
			        // 先执行一次请求
			        await this.getCusdevicesPoints();
			        
			        // 设置1000毫秒后再次执行请求
			        this.requestTimeout = setTimeout(async () => {
			            await this.startPeriodicRequest();
			        }, 1000);
			    } catch (error) {
			        console.log('请求出错，1秒后重试:', error); 
			        // 即使出错也继续定时请求
			        this.requestTimeout = setTimeout(async () => {
			            await this.startPeriodicRequest();
			        }, 1000);
			    }
			},

			handleModelControl() {
				this.isModelControl = true;
			},
			modelSpritesChange(i) {
				this.typeIndex = i;
				this.isModelControl = false;
				this.updateVisualEffects();
			},
			changeAnimation(i) {
				this.animationIndex = i;
			},
			clearModel() {
				if (this.scene !== null && this.scene.children.length > 3) {
					this.scene.children.pop()
					// 必须要清空当前div下的canvas不然canvas会继续叠加
					this.container = document.getElementById('model-container')
					if (this.container !== null) {

						this.container.removeChild(this.container.childNodes[0])
					}
				}
			}, // 模型开始
			//创建相机
			initCamera() {
				this.camera = new THREE.PerspectiveCamera(60, this.container.clientWidth / this.container
					.clientHeight, 1, 100);
				this.camera.position.set(25, 0, 0); //相机位置

			},
			//创建场景
			initScene() {
				this.scene = new THREE.Scene();
				//添加辅助坐标系开始
				// var axes = new THREE.AxesHelper(100);
				// this.scene.add(axes);
				//添加辅助坐标系结束
				// this.scene.background = new THREE.Color("#000000"); 

				this.scene.add(this.camera)
			},
			//光源
			initLight() {
				// 增强半球光配置 
				const light = new THREE.HemisphereLight(0xffffff, 0x444444, 2); // 强度提升至2 
				light.position.set(0, 20, 0);
				this.scene.add(light);

				// 添加平行主光源 
				const directionalLight = new THREE.DirectionalLight(0xffffff, 2);
				directionalLight.position.set(10, 20, 10);
				directionalLight.castShadow = true; // 开启阴影 
				this.scene.add(directionalLight);

				// 补充环境光源 
				const ambientLight = new THREE.AmbientLight(0x404040, 3);
				this.scene.add(ambientLight);
			},
			//视图控制器
			initControls() {
				this.controls = new OrbitControls(this.camera, this.renderer.domElement);
				this.controls.target.set(0, 0, 0);
				this.controls.enableDamping = true; // 添加阻尼效果
				this.controls.dampingFactor = 0.05; // 阻尼系数
				this.controls.update();

			},
			//渲染器
			initRenderer() {
				this.container = document.getElementById('model-container');
				// console.log(this.container, 'this.container');
				this.renderer = new THREE.WebGLRenderer({
					antialias: true, // 关闭抗锯齿
					alpha: true,
					powerPreference: "high-performance",
					logarithmicDepthBuffer: true // 改善深度渲染 
				});
				this.renderer.setPixelRatio(Math.min(1.5, window.devicePixelRatio)); // 限制最大像素比
				// 设置 canvas 元素的样式，包括背景颜色和透明度
				this.renderer.domElement.style.backgroundColor = 'rgba(1,0, 66, 0.5)';
				this.renderer.toneMapping = THREE.ACESFilmicToneMapping; // 高级色调映射 
				this.renderer.toneMappingExposure = 1.2; // 曝光系数 
				this.renderer.setPixelRatio(this.container.devicePixelRatio);
				this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
				this.container.appendChild(this.renderer.domElement);

			},

			// 预创建模型实例
			async createPredefinedModels() {
				const ropeGeometry = new THREE.BoxGeometry(0.01, 0.1, 0.01);
				const ropeMaterial = new THREE.MeshBasicMaterial({
					color: 0x808080
				});

				// 初始化四个钢丝绳组的InstancedMesh
				this.ropeInstancesA = new THREE.InstancedMesh(ropeGeometry, ropeMaterial, this.instanceCount);
				this.ropeInstancesB = new THREE.InstancedMesh(ropeGeometry, ropeMaterial, this.instanceCount);
				this.ropeInstancesC = new THREE.InstancedMesh(ropeGeometry, ropeMaterial, this.instanceCount);
				this.ropeInstancesD = new THREE.InstancedMesh(ropeGeometry, ropeMaterial, this.instanceCount);

				this.scene.add(this.ropeInstancesA);
				this.scene.add(this.ropeInstancesB);
				this.scene.add(this.ropeInstancesC);
				this.scene.add(this.ropeInstancesD);
			},
			//加载设备模型
			// 模型加载方法
			async initGLTF() {
				try {
					await this.loadMainModels();
					await this.loadSensorModels();
					this.loadingInstance.close();
				} catch (error) {
					console.error("模型加载失败:", error);
					this.loadingInstance.close();
				}
			},
			async loadMainModels() {
				const modelUrls = [
					'glbmodel/ztjkxrmx.glb',
					'glbmodel/1yyl.glb',
					'glbmodel/2yylds.glb',
					'glbmodel/3jxdsl.glb',
					'glbmodel/4dzdsl.glb',
					'glbmodel/dz.glb',
					'glbmodel/jxwm.glb',
					'glbmodel/ycm.glb',
					'glbmodel/zcm.glb',
					'glbmodel/jxzm.glb',
					'glbmodel/jxym.glb',
					'glbmodel/ylugss.glb',
					'glbmodel/dzscgss.glb',
					'glbmodel/yjgss.glb',
					'glbmodel/dzgdggss.glb',
					'glbmodel/jxgddgss.glb',
				]; //电梯零部件模型地址 
				this.modelsArray = await this.loadModelsWithGLTFLoader(modelUrls);
				this.setupMainModels();
				this.createPredefinedModels();
				this.cloneAndStackModels(this.currentCount);
			},
			setupMainModels() {
				this.zhitikuangjia = this.modelsArray[0];
				this.zhitikuangjia.visible = true;
				this.zhitikuangjia.position.set(
					this.modelControls.zhitikuangjia.x,
					this.modelControls.zhitikuangjia.y,
					this.modelControls.zhitikuangjia.z
				);
				this.zhitikuangjia.scale.setScalar(2);
				this.zhitikuangjia.rotation.y += Math.PI / 2;
				console.log("直梯框架渲染模型:", this.zhitikuangjia);
				//
				this.yeyinlun = this.modelsArray[1];
				this.yeyinlun.visible = true;
				this.yeyinlun.position.set(
					this.modelControls.yeyinlun.x,
					this.modelControls.yeyinlun.y,
					this.modelControls.yeyinlun.z
				);
				this.yeyinlun.scale.setScalar(2);
				this.yeyinlun.rotation.y += Math.PI / 2;

				console.log("曳引轮:", this.yeyinlun);
				//
				this.yeyinddaoshenlun = this.modelsArray[2];
				this.yeyinddaoshenlun.visible = true;
				this.yeyinddaoshenlun.position.set(
					this.modelControls.yeyinddaoshenlun.x,
					this.modelControls.yeyinddaoshenlun.y,
					this.modelControls.yeyinddaoshenlun.z
				);
				this.yeyinddaoshenlun.scale.setScalar(2);
				this.yeyinddaoshenlun.rotation.y += 0;
				console.log("曳引导绳轮:", this.yeyinddaoshenlun);

				this.jiaoxiangdaoshenlun = this.modelsArray[3];
				this.jiaoxiangdaoshenlun.visible = true;
				this.jiaoxiangdaoshenlun.position.set(
					this.modelControls.jiaoxiangdaoshenlun.x,
					this.modelControls.jiaoxiangdaoshenlun.y,
					this.modelControls.jiaoxiangdaoshenlun.z
				);
				this.jiaoxiangdaoshenlun.scale.setScalar(2);
				this.jiaoxiangdaoshenlun.rotation.y += 0;
				console.log("轿厢导绳轮:", this.jiaoxiangdaoshenlun);

				this.duizhongdaoshenlun = this.modelsArray[4];
				this.duizhongdaoshenlun.visible = true;
				this.duizhongdaoshenlun.position.set(
					this.modelControls.duizhongdaoshenlun.x,
					this.modelControls.duizhongdaoshenlun.y,
					this.modelControls.duizhongdaoshenlun.z
				);
				this.duizhongdaoshenlun.scale.setScalar(2);
				this.duizhongdaoshenlun.rotation.y += Math.PI / 2;
				console.log("对重导绳轮:", this.duizhongdaoshenlun);

				this.duizhong = this.modelsArray[5];
				this.duizhong.visible = true;
				this.duizhong.position.set(
					this.modelControls.duizhong.x,
					this.modelControls.duizhong.y,
					this.modelControls.duizhong.z
				);
				this.duizhong.scale.setScalar(2);
				this.duizhong.rotation.z += Math.PI / 2;
				this.duizhong.rotation.x += -Math.PI / 2;
				console.log("对重:", this.duizhong);

				this.jiaoxiang = this.modelsArray[6];
				this.jiaoxiang.visible = true;
				this.jiaoxiang.position.set(
					this.modelControls.jiaoxiang.x,
					this.modelControls.jiaoxiang.y,
					this.modelControls.jiaoxiang.z
				);
				this.jiaoxiang.scale.setScalar(2);
				this.jiaoxiang.rotation.y += Math.PI / 2;
				console.log("轿厢:", this.jiaoxiang);

				this.youmen1 = this.modelsArray[7].clone();
				this.youmen1.visible = true;
				this.youmen1.position.set(
					this.modelControls.youmen1.x,
					this.modelControls.youmen1.y,
					this.modelControls.youmen1.z
				);
				this.youmen1.scale.setScalar(2);
				this.youmen1.rotation.y += 0;
				this.youmen1.rotation.z += -Math.PI / 2;
				this.youmen1.rotation.x += -Math.PI / 2;
				console.log("1-右层门:", this.youmen1);
				this.scene.add(this.youmen1);

				this.zuomen1 = this.modelsArray[8].clone();
				this.zuomen1.visible = true;
				this.zuomen1.position.set(
					this.modelControls.zuomen1.x,
					this.modelControls.zuomen1.y,
					this.modelControls.zuomen1.z
				);
				this.zuomen1.scale.setScalar(2);
				this.zuomen1.rotation.x += -Math.PI / 2;
				this.zuomen1.rotation.z += Math.PI / 2;
				console.log("1-左层门:", this.zuomen1);
				this.scene.add(this.zuomen1);

				this.youmen2 = this.modelsArray[7].clone();
				this.youmen2.visible = true;
				this.youmen2.position.set(
					this.modelControls.youmen2.x,
					this.modelControls.youmen2.y,
					this.modelControls.youmen2.z
				);
				this.youmen2.scale.setScalar(2);
				this.youmen2.rotation.y += 0;
				this.youmen2.rotation.z += -Math.PI / 2;
				this.youmen2.rotation.x += -Math.PI / 2;
				console.log("2-右层门:", this.youmen2);
				this.scene.add(this.youmen2);

				this.zuomen2 = this.modelsArray[8].clone();
				this.zuomen2.visible = true;
				this.zuomen2.position.set(
					this.modelControls.zuomen2.x,
					this.modelControls.zuomen2.y,
					this.modelControls.zuomen2.z
				);
				this.zuomen2.scale.setScalar(2);
				this.zuomen2.rotation.x += -Math.PI / 2;
				this.zuomen2.rotation.z += Math.PI / 2;
				console.log("2-左层门:", this.zuomen2);
				this.scene.add(this.zuomen2);


				this.doorleft = this.modelsArray[9];
				this.doorleft.visible = true;
				this.doorleft.position.set(
					this.modelControls.doorleft.x,
					this.modelControls.doorleft.y,
					this.modelControls.doorleft.z
				);
				this.doorleft.scale.setScalar(2);
				this.doorleft.rotation.y += Math.PI / 2;
				console.log("轿厢左门:", this.doorleft);
				this.scene.add(this.doorleft);

				this.doorright = this.modelsArray[10];
				this.doorright.visible = true;
				this.doorright.position.set(
					this.modelControls.doorright.x,
					this.modelControls.doorright.y,
					this.modelControls.doorright.z
				);
				this.doorright.scale.setScalar(2);
				this.doorright.rotation.y += Math.PI / 2;
				console.log("轿厢右门:", this.doorright);
				this.scene.add(this.doorright);

				this.yeyinlungangsishen = this.modelsArray[11];
				this.yeyinlungangsishen.visible = true;
				this.yeyinlungangsishen.position.set(
					this.modelControls.yeyinlungangsishen.x,
					this.modelControls.yeyinlungangsishen.y,
					this.modelControls.yeyinlungangsishen.z
				);
				console.log("曳引轮钢丝绳:", this.yeyinlungangsishen.position);
				this.yeyinlungangsishen.scale.setScalar(2);
				this.yeyinlungangsishen.rotation.x += -Math.PI / 2;
				this.yeyinlungangsishen.rotation.z += -Math.PI / 2;
				// doorright.rotation.z += Math.PI /2;
				console.log("曳引轮钢丝绳:", this.yeyinlungangsishen);
				this.scene.add(this.yeyinlungangsishen);

				this.duizhonggangsishen = this.modelsArray[12];
				this.duizhonggangsishen.visible = true;
				this.duizhonggangsishen.position.set(
					this.modelControls.duizhonggangsishen.x,
					this.modelControls.duizhonggangsishen.y,
					this.modelControls.duizhonggangsishen.z
				);
				console.log("对重钢丝绳:", this.duizhonggangsishen.position);
				this.duizhonggangsishen.scale.setScalar(2);
				this.duizhonggangsishen.rotation.x += -Math.PI / 2;
				this.duizhonggangsishen.rotation.z += -Math.PI / 2;
				// doorright.rotation.z += Math.PI /2;
				console.log("对重钢丝绳:", this.duizhonggangsishen);
				this.scene.add(this.duizhonggangsishen);

				this.yijiegangsishen = this.modelsArray[13].clone();
				this.yijiegangsishen.visible = true;
				this.yijiegangsishen.position.set(
					this.modelControls.yijiegangsishen.x,
					this.modelControls.yijiegangsishen.y,
					this.modelControls.yijiegangsishen.z
				);
				console.log("一节钢丝绳:", this.yijiegangsishen.position);
				this.yijiegangsishen.scale.setScalar(2);
				this.yijiegangsishen.rotation.x += -Math.PI / 2;
				this.yijiegangsishen.rotation.z += -Math.PI / 2;
				// doorright.rotation.z += Math.PI /2;
				console.log("一节钢丝绳:", this.yijiegangsishen);
				this.scene.add(this.yijiegangsishen);
				this.duizhonggudingduan = this.modelsArray[14];
				this.duizhonggudingduan.visible = true;
				this.duizhonggudingduan.position.set(
					this.modelControls.duizhonggudingduan.x,
					this.modelControls.duizhonggudingduan.y,
					this.modelControls.duizhonggudingduan.z
				);
				console.log("对重固定端钢丝绳:", this.duizhonggudingduan.position);
				this.duizhonggudingduan.scale.setScalar(2);
				this.duizhonggudingduan.rotation.x += -Math.PI / 2;
				this.duizhonggudingduan.rotation.z += -Math.PI / 2;
				console.log("对重固定端钢丝绳:", this.duizhonggudingduan);
				this.scene.add(this.duizhonggudingduan);

				this.jiaoxianggudingduan = this.modelsArray[15];
				this.jiaoxianggudingduan.visible = true;
				this.jiaoxianggudingduan.position.set(
					this.modelControls.jiaoxianggudingduan.x,
					this.modelControls.jiaoxianggudingduan.y,
					this.modelControls.jiaoxianggudingduan.z
				);
				console.log("轿厢固定端钢丝绳:", this.jiaoxianggudingduan.position);
				this.jiaoxianggudingduan.scale.setScalar(2);
				this.jiaoxianggudingduan.rotation.x += -Math.PI / 2;
				this.jiaoxianggudingduan.rotation.z += Math.PI / 2;
				console.log("轿厢固定端钢丝绳:", this.jiaoxianggudingduan);
				this.scene.add(this.jiaoxianggudingduan);
			},
			async loadSensorModels() {
				const sensorUrls = [
					'glbmodel/GLBstyle/1bmq1jxwy.glb',
					'glbmodel/GLBstyle/2dlcgq.glb',
					'glbmodel/GLBstyle/3dycgq.glb',
					'glbmodel/GLBstyle/4gsjdx.glb',
					'glbmodel/GLBstyle/5jgcjy.glb',
					'glbmodel/GLBstyle/6jgcgqlc.glb',
					'glbmodel/GLBstyle/7ylcgqlc.glb',
					'glbmodel/GLBstyle/8wdcgqrx.glb',
					'glbmodel/GLBstyle/9zscgqsx.glb',
					'glbmodel/GLBstyle/10zdcgqjh.glb'
				];

				this.modelsArray2 = await this.loadModelsWithGLTFLoader(sensorUrls);
				this.setupSensorModels();
				console.log(this.modelsArray2, 'this.modelsArray2')

			},
			// 所有模型加载完成后执行 
			setupSensorModels() {
				//磁编码器1-几何-轿厢位移
				this.bianmaqi1 = this.modelsArray2[0].clone();
				this.bianmaqi1.visible = true;
				this.bianmaqi1.position.set(
					this.modelControls.bianmaqi1.x,
					this.modelControls.bianmaqi1.y,
					this.modelControls.bianmaqi1.z
				);
				this.bianmaqi1.scale.setScalar(10);
				this.bianmaqi1.rotation.y += 0;
				console.log("编码器1:", this.bianmaqi1);
				this.scene.add(this.bianmaqi1);

				// 磁编码器2-几何-曳引轮转速
				this.bianmaqi2 = this.modelsArray2[0].clone();
				this.bianmaqi2.visible = true;
				this.bianmaqi2.position.set(
					this.modelControls.bianmaqi2.x,
					this.modelControls.bianmaqi2.y,
					this.modelControls.bianmaqi2.z
				);
				this.bianmaqi2.scale.setScalar(10);
				this.bianmaqi2.rotation.y += Math.PI / 2;
				console.log("编码器2:", this.bianmaqi2);
				this.scene.add(this.bianmaqi2);

				// 电流传感器1-电学-门机输入电流
				this.dianliu1 = this.modelsArray2[1].clone();
				this.dianliu1.visible = true;
				this.dianliu1.position.set(
					this.modelControls.dianliu1.x,
					this.modelControls.dianliu1.y,
					this.modelControls.dianliu1.z
				);
				this.dianliu1.scale.setScalar(10);
				this.dianliu1.rotation.y += Math.PI / 2;
				this.scene.add(this.dianliu1);

				// 电流传感器2-电学-曳引机U相电流
				this.dianliu2 = this.modelsArray2[1].clone();
				this.dianliu2.visible = true;
				this.dianliu2.position.set(
					this.modelControls.dianliu2.x,
					this.modelControls.dianliu2.y,
					this.modelControls.dianliu2.z
				);
				this.dianliu2.scale.setScalar(2);
				this.dianliu2.rotation.y += Math.PI / 2;
				console.log("电流2:", this.dianliu2);
				this.scene.add(this.dianliu2);



				// 电流传感器3-电学-曳引机V相电流
				this.dianliu3 = this.modelsArray2[1].clone();
				this.dianliu3.visible = true;
				this.dianliu3.position.set(
					this.modelControls.dianliu3.x,
					this.modelControls.dianliu3.y,
					this.modelControls.dianliu3.z
				);
				this.dianliu3.scale.setScalar(2);
				this.dianliu3.rotation.y += Math.PI / 2;
				this.scene.add(this.dianliu3);

				// 电流传感器4-电学-曳引机W相电流
				this.dianliu4 = this.modelsArray2[1].clone();
				this.dianliu4.visible = true;
				this.dianliu4.position.set(
					this.modelControls.dianliu4.x,
					this.modelControls.dianliu4.y,
					this.modelControls.dianliu4.z
				);
				this.dianliu4.scale.setScalar(2);
				this.dianliu4.rotation.y += Math.PI / 2;
				console.log("电流2:", this.dianliu4);
				this.scene.add(this.dianliu4);

				// 电流传感器5-电学-制动器电阻电流
				this.dianliu5 = this.modelsArray2[1].clone();
				this.dianliu5.visible = true;
				this.dianliu5.position.set(
					this.modelControls.dianliu5.x,
					this.modelControls.dianliu5.y,
					this.modelControls.dianliu5.z
				);
				this.dianliu5.scale.setScalar(2);
				this.dianliu5.rotation.y += Math.PI / 2;
				this.scene.add(this.dianliu5);

				// 电流传感器6-电学-制动器线圈1电流
				this.dianliu6 = this.modelsArray2[1].clone();
				this.dianliu6.visible = true;
				this.dianliu6.position.set(
					this.modelControls.dianliu6.x,
					this.modelControls.dianliu6.y,
					this.modelControls.dianliu6.z
				);
				this.dianliu6.scale.setScalar(2);
				this.dianliu6.rotation.y += Math.PI / 2;
				console.log("电流2:", this.dianliu6);
				this.scene.add(this.dianliu6);

				//电流传感器7-电学-制动器线圈2电流
				this.dianliu7 = this.modelsArray2[1].clone();
				this.dianliu7.visible = true;
				this.dianliu7.position.set(
					this.modelControls.dianliu7.x,
					this.modelControls.dianliu7.y,
					this.modelControls.dianliu7.z
				);
				this.dianliu7.scale.setScalar(2);
				this.dianliu7.rotation.y += Math.PI / 2;
				this.scene.add(this.dianliu7);

				// 电流传感器8-电学-制动总电流
				this.dianliu8 = this.modelsArray2[1].clone();
				this.dianliu8.visible = true;
				this.dianliu8.position.set(
					this.modelControls.dianliu8.x,
					this.modelControls.dianliu8.y,
					this.modelControls.dianliu8.z
				);
				this.dianliu8.scale.setScalar(2);
				this.dianliu8.rotation.y += Math.PI / 2;
				console.log("电流2:", this.dianliu8);
				this.scene.add(this.dianliu8);

				// 电压传感器1-电学-门机输入电压
				this.dianya1 = this.modelsArray2[2].clone();
				this.dianya1.visible = true;
				this.dianya1.position.set(
					this.modelControls.dianya1.x,
					this.modelControls.dianya1.y,
					this.modelControls.dianya1.z
				);
				this.dianya1.scale.setScalar(10);
				this.dianya1.rotation.y += Math.PI / 2;
				this.scene.add(this.dianya1);

				//电压传感器2-电学-曳引机U相电压
				this.dianya2 = this.modelsArray2[2].clone();
				this.dianya2.visible = true;
				this.dianya2.position.set(
					this.modelControls.dianya2.x,
					this.modelControls.dianya2.y,
					this.modelControls.dianya2.z
				);
				this.dianya2.scale.setScalar(5);
				this.dianya2.rotation.y += Math.PI / 2;
				this.scene.add(this.dianya2);

				//电压传感器3-电学-曳引机V相电压
				this.dianya3 = this.modelsArray2[2].clone();
				this.dianya3.visible = true;
				this.dianya3.position.set(
					this.modelControls.dianya3.x,
					this.modelControls.dianya3.y,
					this.modelControls.dianya3.z
				);
				this.dianya3.scale.setScalar(5);
				this.dianya3.rotation.y += Math.PI / 2;
				this.scene.add(this.dianya3);

				// 电压传感器4-电学-曳引机W相电压
				this.dianya4 = this.modelsArray2[2].clone();
				this.dianya4.visible = true;
				this.dianya4.position.set(
					this.modelControls.dianya4.x,
					this.modelControls.dianya4.y,
					this.modelControls.dianya4.z
				);
				this.dianya4.scale.setScalar(5);
				this.dianya4.rotation.y += Math.PI / 2;
				this.scene.add(this.dianya4);

				// 电压传感器5-电学-制动器电源电压
				this.dianya5 = this.modelsArray2[2].clone();
				this.dianya5.visible = true;
				this.dianya5.position.set(
					this.modelControls.dianya5.x,
					this.modelControls.dianya5.y,
					this.modelControls.dianya5.z
				);
				this.dianya5.scale.setScalar(10);
				this.dianya5.rotation.y += Math.PI / 2;
				this.scene.add(this.dianya5);

				// 电压传感器6-电学-制动器线圈1电压
				this.dianya6 = this.modelsArray2[2].clone();
				this.dianya6.visible = true;
				this.dianya6.position.set(
					this.modelControls.dianya6.x,
					this.modelControls.dianya6.y,
					this.modelControls.dianya6.z
				);
				this.dianya6.scale.setScalar(5);
				this.dianya6.rotation.y += Math.PI / 2;
				this.scene.add(this.dianya6);

				// 电压传感器7-电学-制动器线圈2电压
				this.dianya7 = this.modelsArray2[2].clone();
				this.dianya7.visible = true;
				this.dianya7.position.set(
					this.modelControls.dianya7.x,
					this.modelControls.dianya7.y,
					this.modelControls.dianya7.z
				);
				this.dianya7.scale.setScalar(5);
				this.dianya7.rotation.y += Math.PI / 2;
				this.scene.add(this.dianya7);

				//高斯计1-电学（电磁）-磁感应强度
				this.gaosiji1 = this.modelsArray2[3].clone();
				this.gaosiji1.visible = true;
				this.gaosiji1.position.set(
					this.modelControls.gaosiji1.x,
					this.modelControls.gaosiji1.y,
					this.modelControls.gaosiji1.z
				);
				this.gaosiji1.scale.setScalar(5);
				this.gaosiji1.rotation.y += Math.PI / 2;
				this.scene.add(this.gaosiji1);

				//高斯计2-电学（电磁）-制动器1余磁
				this.gaosiji2 = this.modelsArray2[3].clone();
				this.gaosiji2.visible = true;
				this.gaosiji2.position.set(
					this.modelControls.gaosiji2.x,
					this.modelControls.gaosiji2.y,
					this.modelControls.gaosiji2.z
				);
				this.gaosiji2.scale.setScalar(5);
				this.gaosiji2.rotation.y += Math.PI / 2;
				this.scene.add(this.gaosiji2);

				//高斯计3-电学（电磁）-制动器2余磁
				this.gaosiji3 = this.modelsArray2[3].clone();
				this.gaosiji3.visible = true;
				this.gaosiji3.position.set(
					this.modelControls.gaosiji3.x,
					this.modelControls.gaosiji3.y,
					this.modelControls.gaosiji3.z
				);
				this.gaosiji3.scale.setScalar(5);
				this.gaosiji3.rotation.y += Math.PI / 2;
				this.scene.add(this.gaosiji3);

				//激光测距仪1-几何-制动器1间隙
				this.jiguangceju1 = this.modelsArray2[4].clone();
				this.jiguangceju1.visible = true;
				this.jiguangceju1.position.set(
					this.modelControls.jiguangceju1.x,
					this.modelControls.jiguangceju1.y,
					this.modelControls.jiguangceju1.z
				);
				this.jiguangceju1.scale.setScalar(5);
				this.jiguangceju1.rotation.y += Math.PI / 2;
				this.scene.add(this.jiguangceju1);

				//激光测距仪2-几何-制动器2间隙
				this.jiguangceju2 = this.modelsArray2[4].clone();
				this.jiguangceju2.visible = true;
				this.jiguangceju2.position.set(
					this.modelControls.jiguangceju2.x,
					this.modelControls.jiguangceju2.y,
					this.modelControls.jiguangceju2.z
				);
				this.jiguangceju2.scale.setScalar(5);
				this.jiguangceju2.rotation.y += Math.PI / 2;
				this.scene.add(this.jiguangceju2);

				//激光传感器-力学-轿厢称重
				this.jiguang = this.modelsArray2[5].clone();
				this.jiguang.visible = true;
				this.jiguang.position.set(
					this.modelControls.jiguang.x,
					this.modelControls.jiguang.y,
					this.modelControls.jiguang.z
				);
				this.jiguang.scale.setScalar(5);
				this.jiguang.rotation.y += Math.PI / 2;
				this.scene.add(this.jiguang);

				//拉压传感器1-力学-门机关门力
				this.laya1 = this.modelsArray2[6].clone();
				this.laya1.visible = true;
				this.laya1.position.set(
					this.modelControls.laya1.x,
					this.modelControls.laya1.y,
					this.modelControls.laya1.z
				);
				this.laya1.scale.setScalar(10);
				this.laya1.rotation.y += Math.PI / 2;
				this.scene.add(this.laya1);

				//拉压传感器2-力学-门机开门力
				this.laya2 = this.modelsArray2[6].clone();
				this.laya2.visible = true;
				this.laya2.position.set(
					this.modelControls.laya2.x,
					this.modelControls.laya2.y,
					this.modelControls.laya2.z
				);
				this.laya2.scale.setScalar(10);
				this.laya2.rotation.y += Math.PI / 2;
				this.scene.add(this.laya2);

				//温度传感器1-热学-曳引机温度
				this.wendu1 = this.modelsArray2[7].clone();
				this.wendu1.visible = true;
				this.wendu1.position.set(
					this.modelControls.wendu1.x,
					this.modelControls.wendu1.y,
					this.modelControls.wendu1.z
				);
				this.wendu1.scale.setScalar(5);
				this.wendu1.rotation.y += Math.PI / 2;
				this.scene.add(this.wendu1);

				//温度传感器2-热学-制动器1温度
				this.wendu2 = this.modelsArray2[7].clone();
				this.wendu2.visible = true;
				this.wendu2.position.set(
					this.modelControls.wendu2.x,
					this.modelControls.wendu2.y,
					this.modelControls.wendu2.z
				);
				this.wendu2.scale.setScalar(5);
				this.wendu2.rotation.y += Math.PI / 2;
				this.scene.add(this.wendu2);

				//温度传感器3-热学-制动器2温度
				this.wendu3 = this.modelsArray2[7].clone();
				this.wendu3.visible = true;
				this.wendu3.position.set(
					this.modelControls.wendu3.x,
					this.modelControls.wendu3.y,
					this.modelControls.wendu3.z
				);
				this.wendu3.scale.setScalar(5);
				this.wendu3.rotation.y += Math.PI / 2;
				this.scene.add(this.wendu3);


				//温度传感器4-热学-曳引轮温度
				this.wendu4 = this.modelsArray2[7].clone();
				this.wendu4.visible = true;
				this.wendu4.position.set(
					this.modelControls.wendu4.x,
					this.modelControls.wendu4.y,
					this.modelControls.wendu4.z
				);
				this.wendu4.scale.setScalar(5);
				this.wendu4.rotation.y += Math.PI / 2;
				this.scene.add(this.wendu4);

				//噪声传感器1-声学-机房噪音
				this.zaoshen1 = this.modelsArray2[8].clone();
				this.zaoshen1.visible = true;
				this.zaoshen1.position.set(
					this.modelControls.zaoshen1.x,
					this.modelControls.zaoshen1.y,
					this.modelControls.zaoshen1.z
				);
				this.zaoshen1.scale.setScalar(10);
				this.zaoshen1.rotation.y += Math.PI / 2;
				this.scene.add(this.zaoshen1);

				//噪声传感器2-声学-轿顶噪音
				this.zaoshen2 = this.modelsArray2[8].clone();
				this.zaoshen2.visible = true;
				this.zaoshen2.position.set(
					this.modelControls.zaoshen2.x,
					this.modelControls.zaoshen2.y,
					this.modelControls.zaoshen2.z
				);
				this.zaoshen2.scale.setScalar(10);
				this.zaoshen2.rotation.y += Math.PI / 2;
				this.scene.add(this.zaoshen2);

				//振动传感器1-几何-轿架振动
				this.zd1 = this.modelsArray2[9].clone();
				this.zd1.visible = true;
				this.zd1.position.set(
					this.modelControls.zd1.x,
					this.modelControls.zd1.y,
					this.modelControls.zd1.z
				);
				this.zd1.scale.setScalar(10);
				this.zd1.rotation.y += Math.PI / 2;
				this.scene.add(this.zd1);

				//振动传感器2-几何-曳引机轴承振动
				this.zd2 = this.modelsArray2[9].clone();
				this.zd2.visible = true;
				this.zd2.position.set(
					this.modelControls.zd2.x,
					this.modelControls.zd2.y,
					this.modelControls.zd2.z
				);
				this.zd2.scale.setScalar(10);
				this.zd2.rotation.y += Math.PI / 2;
				this.scene.add(this.zd2);

				//振动传感器3-几何-右轿门振动
				this.zd3 = this.modelsArray2[9].clone();
				this.zd3.visible = true;
				this.zd3.position.set(
					this.modelControls.zd3.x,
					this.modelControls.zd3.y,
					this.modelControls.zd3.z
				);
				this.zd3.scale.setScalar(10);
				this.zd3.rotation.y += Math.PI / 2;
				this.scene.add(this.zd3);

				//振动传感器4-几何-制动器1振动
				this.zd4 = this.modelsArray2[9].clone();
				this.zd4.visible = true;
				this.zd4.position.set(
					this.modelControls.zd4.x,
					this.modelControls.zd4.y,
					this.modelControls.zd4.z
				);
				this.zd4.scale.setScalar(5);
				this.zd4.rotation.y += Math.PI / 2;
				this.scene.add(this.zd4);

				//振动传感器5-几何-制动器2振动
				this.zd5 = this.modelsArray2[9].clone();
				this.zd5.visible = true;
				this.zd5.position.set(
					this.modelControls.zd5.x,
					this.modelControls.zd5.y,
					this.modelControls.zd5.z
				);
				this.zd5.scale.setScalar(5);
				this.zd5.rotation.y += Math.PI / 2;
				this.scene.add(this.zd5);

				//振动传感器6-几何-左轿门振动
				this.zd6 = this.modelsArray2[9].clone();
				this.zd6.visible = true;
				this.zd6.position.set(
					this.modelControls.zd6.x,
					this.modelControls.zd6.y,
					this.modelControls.zd6.z
				);
				this.zd6.scale.setScalar(10);
				this.zd6.rotation.y += Math.PI / 2;
				this.scene.add(this.zd6);
				for (let i = 0; i < this.modelsArray2.length; i++) {
					this.haveAllDevice(this.modelsArray2[i], i)
				}
				this.updateVisualEffects();
			},
			haveAllDevice(obj, i) {
				obj.traverse(child => {
					if (child.name.includes('传感器') || child.name.includes('高斯计') || child.name.includes('激光')) {
						// console.log(child, '画线的两个点-----child')
						let bBox = new THREE.Box3().setFromObject(child);
						// console.log(bBox, '画线的两个点-----bBox')
						let height = bBox.max.y - bBox.min.y;
						if (isNaN(height)) {
							height = 0;
						}
						let mdlen = bBox.max.x - bBox.min.x; // 模型长度 
						if (isNaN(mdlen)) {
							mdlen = 0;
						}
						let mdwid = bBox.max.z - bBox.min.z; // 模型宽度 
						if (isNaN(mdwid)) {
							mdwid = 0;
						}
						let mdhei = bBox.max.y - bBox.min.y; // 模型高度 
						if (isNaN(mdhei)) {
							mdhei = 0;
						}
						let x1 = bBox.min.x + mdlen / 2; // 模型中心点坐标X
						if (isNaN(x1)) {
							x1 = 0;
						}
						let y1 = bBox.min.y + mdhei / 2; // 模型中心点坐标Y
						if (isNaN(y1)) {
							y1 = 0;
						}
						let z1 = bBox.min.z + mdwid / 2; // 模型中心点坐标Z
						if (isNaN(z1)) {
							z1 = 0;
						}
						let p1 = new THREE.Vector3(
							x1 * this.scaleNum,
							y1 * this.scaleNum,
							z1 * this.scaleNum
						);
						// console.log(p1, '画线的两个点-----p1')
						let p2 = new THREE.Vector3(
							x1 * this.scaleNum + (i % 2 ? (mdwid + 10) : (-mdwid - 10)) * this.scaleNum / 2,
							i % 2 ? y1 * this.scaleNum + i : -y1 * this.scaleNum + 0.8 * i,
							z1 * this.scaleNum
						);
						child.spriteScale = 3 / this.scaleNum; //大小缩放
						child.spritePosition = {
							x: x1 * this.scaleNum + (i % 2 ? (mdwid + 10) : (-mdwid - 10)) * this.scaleNum / 2,
							y: i % 2 ? y1 * this.scaleNum + i : -y1 * this.scaleNum + 0.8 * i,
							z: z1 * this.scaleNum
						};
						child.lineStart = p1;
						child.lineEnd = p2;

						this.allDeviceMeshes.push(child);
						// console.log(this.allDeviceMeshes, '传感器设备')
						this.prepareSpriteForMesh(child); // 预创建精灵图
					}
				});
			},
			// 初始化复制模型
			cloneAndStackModels(count) {
				// 对重钢丝绳A叠加
				this.clonedModels.forEach((model, index) => {
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
				});
				this.clonedModelsA1.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 0.0315;
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
				});
				this.clonedModelsA2.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 0.0315 * 2 + 0.0005;
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
				});
				this.clonedModelsA3.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 0.0315 * 3 + 0.001;
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
				});
				this.clonedModelsA4.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 0.0315 * 4 + 0.0015;
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
				});

				// 对重钢丝绳B叠加
				this.clonedModelsB.forEach((model, index) => {
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.821;
				});
				this.clonedModelsB1.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 0.0315;
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.821;
				});
				this.clonedModelsB2.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 0.0315 * 2 + 0.0005;
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.821;
				});
				this.clonedModelsB3.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 0.0315 * 3 + 0.001;
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.821;
				});
				this.clonedModelsB4.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 0.0315 * 4 + 0.0015;
					model.position.y = this.yijiegangsishen.position.y - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.821;
				});

				// 对重钢丝绳C叠加
				this.clonedModelsC.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 1.729;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.646;
				});
				this.clonedModelsC1.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 1.729;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.646 - 0.0315;
				});
				this.clonedModelsC2.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 1.729;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.646 - 0.032 * 2;
				});
				this.clonedModelsC3.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 1.729;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.646 - 0.032 * 3;
				});
				this.clonedModelsC4.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 1.729;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.646 - 0.032 * 4;
				});

				// 对重钢丝绳D叠加
				this.clonedModelsD.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 2.539;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.652;
				});
				this.clonedModelsD1.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 2.539;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.652 - 0.0315;
				});
				this.clonedModelsD2.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 2.539;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.652 - 0.032 * 2;
				});
				this.clonedModelsD3.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 2.539;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.652 - 0.032 * 3;
				});
				this.clonedModelsD4.forEach((model, index) => {
					model.position.x = this.yijiegangsishen.position.x + 2.539;
					model.position.y = this.yijiegangsishen.position.y - 0.163 - index * 0.02;
					model.position.z = this.yijiegangsishen.position.z - 0.652 - 0.032 * 4;
				});

			},
			async loadModelsWithGLTFLoader(urls) {
				const loader = new GLTFLoader();
				return Promise.all(urls.map(url => {
					return new Promise((resolve, reject) => {
						loader.load(url,
							gltf => {
								gltf.scene.visible = false;
								this.scene.add(gltf.scene);
								resolve(gltf.scene);
							},
							undefined,
							error => {
								console.error(`加载模型失败: ${url}`, error);
								reject(error);
							}
						);
					});
				}));
			},


			disableControls() {
				this.isAnimating = true;
				this.controls.enabled = false;
			},
			enableControls() {
				this.isAnimating = false;
				this.controls.enabled = true;
			},
			elevatorControls(choose) {
				if (this.isAnimating) return; // 如果动画正在运行，直接返回
				this.disableControls(); // 禁用按钮
				if (choose === 1) {
					if (this.jiaoxiang.position.y === -1.031) {
						this.elevatordoorone(); // 第一个函数                          
						setTimeout(() => {
							this.moveElevator(6.978, 0.1, 483, 1); // 第二个函数
							setTimeout(() => {
								this.elevatordoortwo(); // 第三个函数
								this.enableControls(); // 启用按钮
							}, this.totalDuration + 500); // 第三个函数延迟 3500 毫秒
						}, 6500); // 第二个函数延迟 6500 毫秒 

					} else {
						setTimeout(() => {
							this.moveElevator(-1.031, -0.1, 73, 403); // 第一个函数
							setTimeout(() => {
								this.elevatordoorone(); // 第二个函数
								setTimeout(() => {
									this.moveElevator(6.978, 0.1, 483, 1); // 第三个函数
									setTimeout(() => {
										this.elevatordoortwo(); // 第四个函数
										this
											.elevatordoortwo(); // 第四个函数enableControls(); // 启用按钮
									}, this.totalDuration + 500); //第三个函数延迟 500 毫秒
								}, 6500); // 第三个函数延迟 500 毫秒
							}, this.totalDuration + 500); // 第二个函数延迟 500 毫秒
						}, 500); // 第一个函数延迟 6500 毫秒

					}
				} else {
					if (this.jiaoxiang.position.y === 6.978) {
						setTimeout(() => {
							this.elevatordoortwo(); // 第一个函数
							setTimeout(() => {
								this.moveElevator(-1.031, -0.1, 73, 403); // 第二个函数
								setTimeout(() => {
									this.elevatordoorone(); // 第三个函数
									this.enableControls(); // 启用按钮
								}, this.totalDuration + 500); // 第三个函数延迟 500 毫秒
							}, 6500); // 第二个函数延迟 500 毫秒
						}, 500); // 第一个函数延迟 500 毫秒

					} else {

						setTimeout(() => {
							this.moveElevator(6.978, 0.1, 483, 1); // 第一个函数
							setTimeout(() => {
								this.elevatordoortwo(); // 第二个函数
								setTimeout(() => {
									this.moveElevator(-1.031, -0.1, 73, 403); // 第三个函数
									setTimeout(() => {
										this.elevatordoorone(); // 第四个函数
										this.enableControls(); // 启用按钮
									}, this.totalDuration + 500); //第三个函数延迟 500 毫秒
								}, 6500); // 第三个函数延迟 500 毫秒
							}, this.totalDuration + 500); // 第二个函数延迟 500 毫秒
						}, 500); // 第一个函数延迟 6500 毫秒          

					}
				}
			},
			elevatordoorone() {
				// doorleft.visible = false; // 隐藏轿厢模型
				// doorright.visible = false; // 隐藏轿厢模型
				const duration = 1500; // 动画持续时间（1.5 秒）
				const startTime = Date.now();

				const animatedoor1Open = (() => {
					const currentTime = Date.now();
					const elapsedTime = currentTime - startTime;
					const progress = Math.min(elapsedTime / duration, 1); // 计算进度（0 到 1）
					// 计算插值位置
					this.youmen1.position.z = -0.47 + (-1.17 - (-0.47)) * progress; // 一楼右门开的转换
					this.zuomen1.position.z = 0.47 + (1.385 - (0.47)) * progress; // 一楼右门开的转换
					this.modelControls.zuomen1.z = this.zuomen1.position.z; // 轿厢坐标的转换 
					this.modelControls.youmen1.z = this.youmen1.position.z; // 轿厢坐标的转换 
					this.doorleft.position.z = -0.14 + 0.11 + (0.14 + (0.815)) * progress; // 轿厢左门开的转换  
					this.doorright.position.z = -0.211 + (0.211 + (-0.645)) * progress; // 轿厢右门开的转换  
					this.modelControls.doorleft.z = this.doorleft.position.z; // 轿厢左门开坐标的转换 
					this.modelControls.doorright.z = this.doorright.position.z; // 轿厢右门坐标的转换  

					if (progress < 1) {
						requestAnimationFrame(animatedoor1Open); // 继续动画
					}
				})
				animatedoor1Open();
				// 设置 2 秒的等待时间
				setTimeout(() => {
					console.log("2 秒已过，执行某些操作");
					const duration = 1500; // 动画持续时间（1.5 秒）
					const startTime = Date.now();

					const animatedoor1close = (() => {
						const currentTime = Date.now();
						const elapsedTime = currentTime - startTime;
						const progress = Math.min(elapsedTime / duration, 1); // 计算进度（0 到 1）
						// 计算插值位置
						this.youmen1.position.z = -1.17 - (-1.17 - (-0.47)) * progress; // 一楼右门开的转换
						this.zuomen1.position.z = 1.385 - (1.385 - (0.47)) * progress; // 一楼右门开的转换
						this.modelControls.zuomen1.z = this.zuomen1.position.z; // 轿厢坐标的转换 
						this.modelControls.youmen1.z = this.youmen1.position.z; // 轿厢坐标的转换  
						this.doorleft.position.z = 0.815 + 0.11 - (0.14 + (0.815)) *
							progress; // 轿厢左门开的转换  
						this.doorright.position.z = -0.64 - (0.211 + (-0.645)) * progress; // 轿厢右门开的转换  
						this.modelControls.doorleft.z = this.doorleft.position.z; // 轿厢左门开坐标的转换 
						this.modelControls.doorright.z = this.doorright.position.z; // 轿厢右门坐标的转换    
						if (progress < 1) {
							requestAnimationFrame(animatedoor1close); // 继续动画
						} else {
							this.doorleft.visible = true; // 隐藏轿厢模型
							this.doorright.visible = true; // 隐藏轿厢模型
						}
					})
					animatedoor1close();
				}, 3000); // 3000 毫秒 = 3 秒


			},

			elevatordoortwo() {
				const duration = 1500; // 动画持续时间（1.5 秒）
				const startTime = Date.now();

				const animatedoor2Open = (() => {
					const currentTime = Date.now();
					const elapsedTime = currentTime - startTime;
					const progress = Math.min(elapsedTime / duration, 1); // 计算进度（0 到 1）
					// 计算插值位置
					this.youmen2.position.z = -0.47 + (-1.17 - (-0.47)) * progress; // 一楼右门开的转换
					this.zuomen2.position.z = 0.47 + (1.385 - (0.47)) * progress; // 一楼右门开的转换
					this.modelControls.zuomen1.z = this.zuomen1.position.z; // 轿厢坐标的转换 
					this.modelControls.youmen1.z = this.youmen1.position.z; // 轿厢坐标的转换 
					this.doorleft.position.z = -0.14 + 0.11 + (0.14 + (0.815)) * progress; // 轿厢左门开的转换  
					this.doorright.position.z = -0.211 + (0.211 + (-0.645)) * progress; // 轿厢右门开的转换  
					this.modelControls.doorleft.z = this.doorleft.position.z; // 轿厢左门开坐标的转换 
					this.modelControls.doorright.z = this.doorright.position.z; // 轿厢右门坐标的转换  
					if (progress < 1) {
						requestAnimationFrame(animatedoor2Open); // 继续动画
					}
				});
				animatedoor2Open();
				// 设置 2 秒的等待时间
				setTimeout(() => {
					console.log("2 秒已过，执行某些操作");
					const duration = 1500; // 动画持续时间（1.5 秒）
					const startTime = Date.now();

					const animatedoor2close = (() => {
						const currentTime = Date.now();
						const elapsedTime = currentTime - startTime;
						const progress = Math.min(elapsedTime / duration, 1); // 计算进度（0 到 1）
						// 计算插值位置
						this.youmen2.position.z = -1.17 - (-1.17 - (-0.47)) * progress; // 一楼右门开的转换
						this.zuomen2.position.z = 1.385 - (1.385 - (0.47)) * progress; // 一楼右门开的转换
						this.modelControls.zuomen1.z = this.zuomen1.position.z; // 轿厢坐标的转换 
						this.modelControls.youmen1.z = this.youmen1.position.z; // 轿厢坐标的转换  
						this.doorleft.position.z = 0.815 + 0.11 - (0.14 + (0.815)) *
							progress; // 轿厢左门开的转换  
						this.doorright.position.z = -0.64 - (0.211 + (-0.645)) * progress; // 轿厢右门开的转换  
						this.modelControls.doorleft.z = this.doorleft.position.z; // 轿厢左门开坐标的转换 
						this.modelControls.doorright.z = this.doorright.position.z; // 轿厢右门坐标的转换    
						if (progress < 1) {
							requestAnimationFrame(animatedoor2close); // 继续动画
						} else {
							this.doorleft.visible = true; // 隐藏轿厢模型
							this.doorright.visible = true; // 隐藏轿厢模型
						}
					})
					animatedoor2close();
				}, 3000); // 3000 毫秒 = 3 秒

			},
			roundToThree(num) {
				return Math.round(num * 1000) / 1000;
			},
			// 动画函数
			easeInOutQuad(t) {
				return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
			},

			moveElevator(deltaY, cho, weizhi1, weizhi2) {
				if (Math.abs(deltaY - this.jiaoxiang.position.y) < 0.001) {
					console.log("目标位置与当前位置相同，无需移动");
					this.enableControls()
					return;
				} else {
					const startY = this.jiaoxiang.position.y; // 轿厢当前位置
					const startYDZDZ = this.duizhong.position.y; // 对重当前位置
					const deltaYTotal = deltaY - startY;
					const total_s = 8.009; //整体位移距离

					const a1 = this.roundToThree(this.Acce); //加速度
					const t1 = this.roundToThree(this.Vm / a1); //加速阶段时间
					const s1 = a1 * t1 * t1 / 2

					const s2 = this.St - 2 * s1;
					const t2 = this.roundToThree(s2 / this.Vm); //匀速阶段时间

					const t3 = t1; //减速阶段时间

					const s11 = s1 / this.St * total_s;
					const a = this.roundToThree(2 * s11 / (t1 * t1));; //加速阶段加速度

					const a_decel = -1 * this.roundToThree(2 * s11 / (t1 * t1));; //减速阶段加速度

					this.totalDuration = (t1 + t2 + t3) * 1000;
					console.log("电梯运行时间", this.totalDuration)
					const startTime = Date.now();
					const animate = (() => {
						const currentTime = Date.now();
						const elapsedTime = currentTime - startTime;
						const elapsedSeconds = elapsedTime / 1000;
						let s_current = 0;

						// 三阶段位移计算
						if (elapsedSeconds < t1) {
							s_current = 0.5 * a * elapsedSeconds * elapsedSeconds;
						} else if (elapsedSeconds < t1 + t2) {
							const v_max = a * t1;
							s_current = 0.5 * a * t1 * t1 + v_max * (elapsedSeconds - t1);
						} else if (elapsedSeconds <= t1 + t2 + t3) {
							const v_max = a * t1;
							const t_decel = elapsedSeconds - t1 - t2;
							s_current = 0.5 * a * t1 * t1 + v_max * t2 + (v_max * t_decel + 0.5 * a_decel *
								t_decel * t_decel);
						} else {
							s_current = total_s;
						}

						const progress = Math.min(s_current / total_s); // 计算进度（0 到 1）
						const displacement = deltaYTotal * this.easeInOutQuad(progress); // 使用缓动函数



						// 更新轿厢系统
						this.jiaoxiang.position.y = startY + displacement;
						this.modelControls.jiaoxiang.y = this.jiaoxiang.position.y;
						this.jiaoxiangdaoshenlun.position.y = startY + 0.726 + displacement;
						this.modelControls.jiaoxiangdaoshenlun.y = this.jiaoxiangdaoshenlun.position.y;
						this.doorleft.position.y = startY - 0.169 + displacement;
						this.doorright.position.y = startY - 0.169 + displacement;

						// 更新传感器组
						this.dianliu1.position.y = startY - 0.429 + displacement;
						this.dianya1.position.y = startY - 0.579 + displacement;
						this.laya1.position.y = startY - 0.813 + displacement;
						this.laya2.position.y = startY - 0.813 + displacement;
						this.zaoshen2.position.y = startY - 1.239 + displacement;
						this.zd1.position.y = startY - 1.319 + displacement;
						this.zd3.position.y = startY - 1.319 + displacement;
						this.zd6.position.y = startY - 1.319 + displacement;

						// 更新对重系统
						this.duizhong.position.y = startYDZDZ - displacement;
						this.modelControls.duizhong.y = this.duizhong.position.y;
						this.duizhongdaoshenlun.position.y = startYDZDZ + 2.706 - displacement;
						this.modelControls.duizhongdaoshenlun.y = this.duizhongdaoshenlun.position.y;
						this.duizhonggangsishen.position.y = startYDZDZ + 5.45 - displacement;
						this.modelControls.duizhonggangsishen.y = this.duizhonggangsishen.position.y;

						// 更新轮系旋转
						this.yeyinlun.rotateX(-cho * 2);
						this.yeyinddaoshenlun.rotation.z += cho;
						this.jiaoxiangdaoshenlun.rotation.z += cho;
						this.duizhongdaoshenlun.rotation.x += cho;

						// 钢丝绳动态生成逻辑
						const targetCount = weizhi1;
						const startCount = this.currentCount;
						const currentFrameCount = Math.floor(startCount + (targetCount - startCount) * progress);

						// 移除旧模型
						[this.clonedModels, this.clonedModelsA1, this.clonedModelsA2, this.clonedModelsA3, this
							.clonedModelsA4,
							this.clonedModelsB, this.clonedModelsB1, this.clonedModelsB2, this.clonedModelsB3, this
							.clonedModelsB4,
							this.clonedModelsC, this.clonedModelsC1, this.clonedModelsC2, this.clonedModelsC3, this
							.clonedModelsC4,
							this.clonedModelsD, this.clonedModelsD1, this.clonedModelsD2, this.clonedModelsD3, this
							.clonedModelsD4
						]
						.forEach(arr => arr.forEach(model => this.scene.remove(model)));
						// 生成新模型
						for (let i = 0; i < this.currentFrameCount; i++) {
							// 生成钢丝绳A组
							const createRope = (xOffset, zOffset = 0) => {
								const model = this.yijiegangsishen.clone();
								model.position.set(
									this.yijiegangsishen.position.x + xOffset,
									this.yijiegangsishen.position.y - i * 0.02,
									this.yijiegangsishen.position.z + zOffset
								);
								this.scene.add(model);
								return model;
							};

							this.clonedModels.push(createRope(0));
							this.clonedModelsA1.push(createRope(0.0315));
							this.clonedModelsA2.push(createRope(0.0635));
							this.clonedModelsA3.push(createRope(0.0945));
							this.clonedModelsA4.push(createRope(0.126));

							// 生成钢丝绳B组
							this.clonedModelsB.push(createRope(0, -0.821));
							this.clonedModelsB1.push(createRope(0.0315, -0.821));
							this.clonedModelsB2.push(createRope(0.0635, -0.821));
							this.clonedModelsB3.push(createRope(0.0945, -0.821));
							this.clonedModelsB4.push(createRope(0.126, -0.821));
						}

						// 生成C、D组钢丝绳
						const targetCount2 = weizhi2;
						const startCount2 = this.currentCount2;
						const currentFrameCount1 = Math.floor(startCount2 + (targetCount2 - startCount2) *
							progress);

						for (let i = 0; i < currentFrameCount1; i++) {
							// 生成钢丝绳C组
							const createCRope = (xOffset, zOffset) => {
								const model = this.yijiegangsishen.clone();
								model.position.set(
									this.yijiegangsishen.position.x + 1.729 + xOffset,
									this.yijiegangsishen.position.y - 0.163 - i * 0.02,
									this.yijiegangsishen.position.z - 0.646 + zOffset
								);
								this.scene.add(model);
								return model;
							};

							this.clonedModelsC.push(createCRope(0, 0));
							this.clonedModelsC1.push(createCRope(0, -0.0315));
							this.clonedModelsC2.push(createCRope(0, -0.063));
							this.clonedModelsC3.push(createCRope(0, -0.0945));
							this.clonedModelsC4.push(createCRope(0, -0.126));

							// 生成钢丝绳D组
							const createDRope = (xOffset, zOffset) => {
								const model = this.yijiegangsishen.clone();
								model.position.set(
									this.yijiegangsishen.position.x + 2.539 + xOffset,
									this.yijiegangsishen.position.y - 0.163 - i * 0.02,
									this.yijiegangsishen.position.z - 0.652 + zOffset
								);
								this.scene.add(model);
								return model;
							};

							this.clonedModelsD.push(createDRope(0, 0));
							this.clonedModelsD1.push(createDRope(0, -0.0315));
							this.clonedModelsD2.push(createDRope(0, -0.063));
							this.clonedModelsD3.push(createDRope(0, -0.0945));
							this.clonedModelsD4.push(createDRope(0, -0.126));
						}

						// 动画循环控制
						if (elapsedTime < this.totalDuration) {
							requestAnimationFrame(animate);
						} else {
							this.enableControls()
							this.currentCount = targetCount;
							this.currentCount2 = targetCount2;
							// 最终位置校准
							this.jiaoxiang.position.y = startY + deltaYTotal;
							this.duizhong.position.y = startYDZDZ - deltaYTotal;
						}
					})
					animate();
				}
			},
			// 精灵图相关方法
			prepareSpriteForMesh(mesh) {
				const canvas = this.createSpriteCanvas(mesh.name);
				const texture = new THREE.Texture(canvas);
				texture.needsUpdate = true;

				mesh.spriteMaterial = new THREE.SpriteMaterial({
					map: texture,
					transparent: true,
					opacity: 0.9,
					visible: false
				});

				mesh.sprite = new THREE.Sprite(mesh.spriteMaterial);
				mesh.sprite.scale.set(
					mesh.spriteScale,
					mesh.spriteScale,
					mesh.spriteScale
				);
				mesh.sprite.position.set(
					mesh.spritePosition.x,
					mesh.spritePosition.y,
					mesh.spritePosition.z
				);
				this.scene.add(mesh.sprite);
			},

			createSpriteCanvas(deviceName) {
				const canvas = document.createElement('canvas');
				const context = canvas.getContext('2d');
				canvas.width = 600;
				canvas.height = 600;

				context.lineJoin = "round";
				context.lineCap = 'round';
				context.miterLimit = 2;
				context.lineWidth = 5;

				const imgBg1 = document.getElementById('completeBg');
				if (imgBg1) {
					context.drawImage(imgBg1, 0, 0, 600, 280);
				}

				context.fillStyle = "#fff";
				context.font = "60px bold Arial";
				context.fillText(deviceName, 40, 130);

				return canvas;
			},
			// 更新视觉效果
			updateVisualEffects() {
				// 清除旧效果
				this.allDeviceMeshes.forEach(item => {
					if (item.lines) {
						item.lines.forEach(line => this.scene.remove(line));
					}
				});
				this.currentSprites.forEach(sprite => sprite.material.visible = false);
				this.currentOutlineObjects = [];
				// 获取当前类型对应的mesh名称模式
				const targetPattern = this.typeMeshMap[this.typeIndex];
				// 查找匹配的mesh
				this.allDeviceMeshes.forEach(mesh => {
					if (mesh.name.includes(targetPattern)) {
						mesh.sprite.material.visible = true;
						mesh.sprite.scale.set(mesh.spriteScale, mesh.spriteScale, mesh.spriteScale); //大小缩放
						mesh.sprite.position.set(mesh.spritePosition.x, mesh.spritePosition.y, mesh
							.spritePosition
							.z); //位置

						if (!mesh.lines) mesh.lines = [];
						const line = this.initSpriteLine(
							mesh.lineStart,
							mesh.lineEnd
						);
						mesh.lines.push(line);
						this.scene.add(line);
						this.currentSprites.push(mesh.sprite);
						this.currentOutlineObjects.push(mesh);
					}
				});
				// 更新呼吸灯效果
				if (this.outlinePass) {
					this.outlinePass.selectedObjects = this.currentOutlineObjects;
				}
			},

			// 创建动态精灵图画布
			createSpriteCanvas(deviceName) {
				const canvas = document.createElement('canvas');
				const context = canvas.getContext('2d');
				canvas.width = 600;
				canvas.height = 600;
				context.lineJoin = "round";
				context.lineCap = 'round';
				context.miterLimit = 2;
				context.lineWidth = 5; //borderWidth

				var imgBg1 = document.getElementById('completeBg')
				if (imgBg1) {
					context.drawImage(imgBg1, 0, 0, 600, 280) //坐标x，坐标y,图片宽，图片高 
				}
				// 绘制图标结束 
				context.fillStyle = "#fff";
				context.font = "60px bold Arial";
				context.lineHeight = '60px'
				context.fillText(deviceName, 40, 130);

				return canvas;
			},

			initSpriteLine(p1, p2) {
				// 定义几何体
				const geometry = new THREE.BufferGeometry();
				const pointsArray = new Array();
				const colorsArray = new Array();
				// 定义连接线的材质
				let material = new THREE.LineBasicMaterial({
					color: 0x00FF00,
					// vertexColors: THREE.VertexColors, // //以顶点颜色为准 
					// side: THREE.DoubleSide
				});
				// 用 THREE.Vector3 来创建用来连接模型和标注的线的两个端点
				// 把端点加入到几何体中
				pointsArray.push(p1);
				pointsArray.push(p2);
				geometry.setFromPoints(pointsArray)
				// 设置端点颜色 
				// 定义连接线实例对象
				return new THREE.Line(geometry, material);


			},

			animate() {
				const targetFPS = 60;
				let then = Date.now();
				const interval = 1000 / targetFPS;

				const loop = () => {
					const now = Date.now();
					const delta = now - then;

					if (delta > interval) {
						then = now - (delta % interval);
						// 执行渲染逻辑
						if (this.composer) {
							this.composer.render();
						}

					}
					this.animateId = requestAnimationFrame(loop);
				};
				loop();

			},
			init() {
				this.initRenderer()
				this.initCamera()
				this.initScene()
				this.initLight()
				this.initGLTF()
				this.initControls();
				this.initOutline();
			},
			//高亮显示模型（呼吸灯）
			initOutline() {
				// console.log(selectedObjects, 'selectedObjects')
				// 创建一个EffectComposer（效果组合器）对象，然后在该对象上添加后期处理通道。
				if (this.renderer) {
					this.composer = new EffectComposer(this.renderer)
					// // 新建一个场景通道  为了覆盖到原来的场景上
					this.renderPass = new RenderPass(this.scene, this.camera)
					this.composer.addPass(this.renderPass);
					// 物体边缘发光通道
					this.outlinePass = new OutlinePass(
						new THREE.Vector2(this.container.clientWidth, this.container.clientHeight),
						this.scene,
						this.camera
					);
					this.outlinePass.edgeStrength = 2.0;
					this.outlinePass.edgeThickness = 1;
					this.outlinePass.downSampleRatio = 3;
					this.outlinePass.selectedObjects = this.currentOutlineObjects;
					this.outlinePass.pulsePeriod = 5 // 呼吸闪烁的速度
					this.outlinePass.visibleEdgeColor.set(parseInt(0x00FF00)) // 呼吸显示的颜色
					this.outlinePass.hiddenEdgeColor = new THREE.Color(0, 0, 0) // 呼吸消失的颜色
					this.outlinePass.clear = true
					this.composer.addPass(this.outlinePass)
					// 自定义的着色器通道 作为参数
					// let effectFXAA = new ShaderPass(FXAAShader)
					// effectFXAA.uniforms.resolution.value.set(1 / window.innerWidth, 1 / window.innerHeight)
					// effectFXAA.renderToScreen = true
					// this.composer.addPass(effectFXAA)
					const gammaPass = new ShaderPass(GammaCorrectionShader);
					this.composer.addPass(gammaPass);
				}
			},
			floorAni(floor, status) {
				const value = parseFloat(this.Vm);
				if (isNaN(value)) {
					this.$message.error('请输入有效的数字');
				} else if (value <= 0 || value > 1.15) {
					this.$message.error('输入运行速度的数字必须在 0 - 1.15 之间');
				} else {
					console.log(this.Vm, '运行速度正常');
					const valuea = parseFloat(this.Acce);
					if (isNaN(valuea)) {
						this.$message.error('请输入有效的数字');

					} else if (valuea <= 0 || valuea > 1) {
						this.$message.error('输入加速度的数字必须在 0 - 1.00 之间');
					} else {
						const elevatorPositions = {
							floor1Y: -1.031,
							floor2Y: 6.978,
							up: 0.1,
							down: -0.1,
							floor1c: 1,
							floor2c: 0,
							gangsiAA: 73,
							gangsiAB: 483,
							gangsiCA: 403,
							gangsiCB: 1
						};
						this.animationIndex = floor;
						this.isAnimating = true;
						if (floor == 1 && status == 'up') {
							this.moveElevator(elevatorPositions.floor2Y, elevatorPositions.up, elevatorPositions.gangsiAB,
								elevatorPositions.gangsiCB)
						} else if (floor == 2 && status == 'down') {
							this.moveElevator(elevatorPositions.floor1Y, elevatorPositions.down, elevatorPositions
								.gangsiAA,
								elevatorPositions.gangsiCA)
						}
					}
				}


			},
			doorAni(floor) {
				const elevatorPositions = {
					floor1Y: -1.031,
					floor2Y: 6.978,
					up: 0.1,
					down: -0.1,
					floor1c: 1,
					floor2c: 0,
					gangsiAA: 73,
					gangsiAB: 483,
					gangsiCA: 403,
					gangsiCB: 1
				};
				if (floor === 1) {
					this.animationIndex = 3;
					this.elevatordoorone(elevatorPositions.down) // 一楼电梯
				} else {
					this.animationIndex = 4;
					this.elevatordoortwo(elevatorPositions.down)
				}
			},
			operationAni(floor) {

				if (floor === 1) {
					this.animationIndex = 5;
					this.elevatorControls(1); // 一楼电梯
				} else {
					this.animationIndex = 6;
					this.elevatorControls(0)
				}
			},
			// 模型结束   
			initData() {
				const date = new Date();
				// 初始化年月日
				let day = date.getDate();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let hour = date.getHours();
				let minute = date.getMinutes();
				let second = date.getSeconds();
				month = month < 10 ? '0' + month : month;
				day = day < 10 ? '0' + day : day;
				hour = hour < 10 ? '0' + hour : hour;
				minute = minute < 10 ? '0' + minute : minute;
				second = second < 10 ? '0' + second : second;
				this.currentDateTime = `${year}-${month}-${day} ${hour}:${minute}:${second}`
			},

		}
	};
</script>

<style lang="scss" scoped>
	@import "@/styles/variables.scss";

	.preventClick {
		pointer-events: none;
		opacity: 0.4;
	}

	.app-right-container {
		overflow: hidden;
	}

	.model-container {
		width: 100%;
		height: 100%;
		position: relative;

		.current-time {
			width: 160px;
			height: 50px;
			line-height: 50px;
			text-align: center;
			position: absolute;
			top: 10px;
			left: 10px;
			z-index: 10;
		}
	}

	#model-container {
		width: 100%;
		height: 100%;
		position: absolute;
		top: 0;
		left: 0;
	}

	.model-control-container {
		width: 180px;
		height: 50px;
		line-height: 50px;
		text-align: center;
		box-shadow: 0px 0px 20px $mainBgColor inset;
		border-radius: 5px;
		position: absolute;
		bottom: 20px;
		right: 20px;
		z-index: 10;
	}

	.model-handel-container {
		width: 140px;
		// height: 100px;
		// background: linear-gradient(rgba(0, 0, 0, 0.4) 0%, rgba(0, 0, 0, 0.2) 20%, rgba(0, 0, 0, 0) 100%);
		position: absolute;
		top: 0;
		right: 0;
		z-index: 10;
		padding-top: 20px;


	}

	.model-handel-btn {
		width: 120px;
		height: 50px;
		line-height: 50px;
		text-align: center;
		box-shadow: 0px 0px 20px $mainBgColor inset;
		border-radius: 5px;
		margin-top: 20px !important;
		color: $mainTextColor
	}

	.handle-active {
		color: $menuActiveText !important;
		background: #006afe !important;
	}

	#model-container canvas {
		width: 100% !important;
	}

	.app-right-container {
		.app-right-title {
			width: 100%;
			height: 45px;
			line-height: 45px;
			padding: 0 20px !important;
		}



		.app-controls-container {
			height: calc(100% - 45px);
			width: 100%;
			transition: none 0s ease 0s !important;
			margin-top: 0px !important;

			.app-controls-title {
				margin-top: 40px !important;
			}

			.model-controls-btns {
				width: 60%;
			}
		}
	}
</style>